export default function toThousands(num) {
    num = (num || 0).toString()
    let result = ''
    while (num.length > 3) {
        result = ',' + num.slice(-3) + result
        num = num.slice(0, num.length - 3)
    }
    if (num) {
        result = num + result
    }

    // 获取result的小数点‘.’的索引
    const n = result.indexOf('.')
    const strIndex = result.indexOf('.')
    // 如果有'.'
    if (n !== -1) {
        //  把'.'两侧的字符串拼接在一期，去掉最后这个','
        const result1 = result.substring(0, strIndex - 1)
        const result2 = result.substring(strIndex, result.length)
        result = result1 + result2
    }
    return result
}
